package com.xiaoshuidi.cloud.module.member.controller.admin.index;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.module.member.controller.admin.index.vo.AppIndexConfigEntityVO;
import com.xiaoshuidi.cloud.module.member.controller.admin.index.vo.AppIndexConfigPageVo;
import com.xiaoshuidi.cloud.module.member.controller.admin.index.vo.SetAppIndexConfigVo;
import com.xiaoshuidi.cloud.module.member.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.member.pojo.index.AppIndexConfigEntity;
import com.xiaoshuidi.cloud.module.member.service.index.AppIndexPageConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Tag(name = "后台管理- App配置")
@RestController
@RequestMapping(ApiConstants.NAME + "/admin-app-config")
@Validated
@Slf4j
public class AppIndexPageAdminController {

    @Resource
    AppIndexPageConfigService appIndexPageConfigService;

    @PostMapping("/page")
    @Operation(summary = "租客端推荐配置列表")
    public CommonResult<List<AppIndexConfigEntityVO>> appConfigsPage() {
        List<AppIndexConfigEntityVO> list = appIndexPageConfigService.appIndexConfigList();
        return CommonResult.success(list);
    }

    @PostMapping("/reset")
    @Operation(summary = "重置")
    public CommonResult<Boolean> appConfigReset() {
        appIndexPageConfigService.resetAppIndexPageConfigs();
        return CommonResult.success(Boolean.TRUE);
    }

    @PostMapping("/update")
    @Operation(summary = "设置配置")
    public CommonResult<Boolean> setAppIndexPageConfig(@RequestBody SetAppIndexConfigVo form) {
        appIndexPageConfigService.setAppIndexPageConfig(form);
        return CommonResult.success(Boolean.TRUE);
    }
}
